<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<?php
session_start();
require_once 'code/Tasks.php';
require_once 'code/Util.php';
?>
<html>
    <head>
        <link rel="shortcut icon" href="images/iTrack.ico"> 
        <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="PRIVATE">
        <META HTTP-EQUIV="CONTENT-LANGUAGE" CONTENT="en-US">
        <META NAME="DESCRIPTION" CONTENT="Tasks application home page">
        <META NAME="KEYWORDS" CONTENT="iTrack">
        <META NAME="COPYRIGHT" CONTENT="&copy; iTrack 2013">

        <title>iTrack - People</title>

        <link href="assets/css/bootstrap.css" rel="stylesheet">
        <style type="text/css">
            body {
                padding-top: 60px;
            }
        </style>
        <link href="assets/css/bootstrap-responsive.css" rel="stylesheet">

        <script type="text/javascript">
            $(document).ready(function() {

            });

            function CreateProjectPopup() {
                ClearProjectPopup();		

                $('#txtProjectName').focus();
                $('#myModal').modal('show');

            }
            function ClearProjectPopup() {
                $("#txtProjectName").val("");
                $("#txtProjectDescription").val("");
                $("#loading").hide();		
            }

            function SaveProject() {
                var projectname = $("#txtProjectName").val();
                var projectdesc = $("#txtProjectDescription").val();
                var userid = $("#userid").val();

                if(projectname != "") {
                    $("#loading").show();
                    
                    $.ajax({         
                        url: 'controller.php', 
                        type: 'GET',
                        timeout:4000,
                        dataType: 'json',
                        data: { 
                            'action': 'saveproject',
                            'userid': userid,
                            'projectid':'0',
                            'projectname': projectname,
                            'projectdesc':projectdesc
                        },         
                        success: function(data) {
                            $("#loading").hide();
                            //alert(data);
                            if (data != null) {
                                if (data.result == "success") {
                                    $('#myModal').modal('hide');
                                    document.location.reload(true);
                                } else {
                                    $("#error_message").html("Error saving project !");
                                }
                            } else {
                                $("#error_message").html("Error saving project !");
                            }                                                               
                        }, error: function (xhr, ajaxOptions, thrownError) {
                            $("#loading").hide();
                            $("#error_message").html("Error saving project !");
                            //alert(xhr.status);
                            //alert(thrownError);
                        }
                    });                
                } else {
                    $("#error_message").html("Please enter project details !");
                    $('#txtProjectName').focus();
                }
                return false;
            }

            function ViewProject(projectid) {
                //alert("Project Id = " + projectid);
                if((projectid != null) &&(projectid != "0")) {
                    window.location = "viewproject.php?projectid=" + projectid;
                } 		
            }
        </script>
        <style type="text/css">
            .sidebar-nav {
                padding: 9px 0;
            }
            .listcontents {
                padding:10px;
            }
			.circular {
				align:center;
				margin:10px;
			}
        </style>    
    </head>
    <body>
        <?php
        if (isset($_SESSION['userid'])) {
            ?>

            <input type="hidden" id="userid" name="userid" value="<?php echo $_SESSION['userid']; ?>">

            <?php
            Util::getNavBar();
            ?>
            
            <div class="container-fluid">
                <div class="row-fluid">
                    <div class="span2">
                        <div class="well sidebar-nav">
                            <?php
                            echo Util::getLeftNavList('People');
                            ?>
                        </div><!--/.well -->
                    </div><!--/span-->
                    <div class="span10">          
                        <div class="row-fluid">
                            <div class="span12">
                                <h2>People</h2>
                                <!--<a href="#myModal" role="button" class="btn btn-primary" onclick="CreateProjectPopup()">Create New</a>-->
                                <br></br>
                                <?php
                                $objProject = new Tasks();
                                $projects = $objProject->getActiveUsers($_SESSION['userid']);
                                if (count($projects) > 0) {
                                    ?>
                                    <div class="row-fluid">
										<form class="form-inline">
										  <input type="text" class="form-control" placeholder="search people">
										  <button type="submit" class="btn btn-default">Go</button>
										</form>
									</div>
									<div class="row-fluid">
                                        <?php
                                        foreach ($projects as $db_field) {
                                            ?>
                                            <div class="span2 well" style="min-height:150px;">
                                                <h3><?php echo $db_field['ufname'] . ' ' . $db_field['ulname']; ?></h3> 
												<div class="muted"><?php echo $db_field['jobrole']; ?></div>
                                                
													<div class="circular"><img src="<?php echo $db_field['picpath']; ?>" alt="" /></div>
												
                                                <p><a class="btn" href="viewproject.php?projectid=<?php echo $db_field['id']; ?>">View details &raquo;</a></p>
                                            </div><!--/span-->
                                            <?php
                                        }
                                        ?>
                                    </div><!--/row-->
                                    <?php
                                }
                                ?>

                            </div><!--/span-->           
                        </div><!--/row-->

                    </div><!--/span-->
                </div><!--/row-->

                <!-- Include footer -->
                <?php include_once 'footer.php'; ?>
            </div>


            <!-- Dialogs -->
            <div class="modal hide fade in" id="myModal" tabindex="-1"
                 role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"
                 style="width: 25em">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                            aria-hidden="true">&times;</button>
                    <h3 id="myModalLabel"><i class="icon-bullhorn"></i>&nbsp;Create New Project</h3>
                </div>
                <div class="modal-body">
                    <div class="control-group">
                        <div class="controls">
                            <label class="control-label" for="txtProjectName"><abbr
                                    title="Project Name">Project Name</abbr></label>
                            <div class="controls">
                                <input type="text" class="input-xlarge" id="txtProjectName"
                                       name="txtProjectName" autofocus>
                            </div>
                        </div>
                        <div class="controls">
                            <label class="control-label" for="txtProjectDescription"><abbr
                                    title="Project Description">Description</abbr></label>
                            <div class="controls">
                                <textarea class="input-xlarge" id="txtProjectDescription"
                                          name="txtProjectDescription" rows="5"></textarea>
                            </div>
                            <div class="controls">
                                <span id="error_message" class="text-error"></span>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <span id="loading" class="pull-left"><img src="images/loadera16.gif"></span>
                    <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
                    <button class="btn btn-primary" onclick="SaveProject()">Save</button>
                </div>
            </div>


            <!-- Placed at the end of the document so the pages load faster -->
            <script src="assets/js/jquery.js"></script>
            <script src="assets/js/bootstrap-transition.js"></script>
            <script src="assets/js/bootstrap-alert.js"></script>
            <script src="assets/js/bootstrap-modal.js"></script>
            <script src="assets/js/bootstrap-dropdown.js"></script>
            <script src="assets/js/bootstrap-scrollspy.js"></script>
            <script src="assets/js/bootstrap-tab.js"></script>
            <script src="assets/js/bootstrap-tooltip.js"></script>
            <script src="assets/js/bootstrap-popover.js"></script>
            <script src="assets/js/bootstrap-button.js"></script>
            <script src="assets/js/bootstrap-collapse.js"></script>
            <script src="assets/js/bootstrap-carousel.js"></script>
            <script src="assets/js/bootstrap-typeahead.js"></script>

            <?php
        } else {
            header("location: login.php");
        }
        ?> 
    </body>
</html>